package config

import (
	"github.com/cloudwego/hertz/pkg/common/hlog"
	"gopkg.in/yaml.v2"
	"io/ioutil"
)

type Set struct {
	Redis Redis
	Mode  string `yaml:"mode"`
	Db    Db
	File  File
}

type File struct {
	Path string `yaml:"path"`
}
type Redis struct {
	Host      string `yaml:"host"`
	Port      int    `yaml:"port"`
	Password  string `yaml:"password"`
	Timeout   int    `yaml:"timeout"`
	MaxActive int    `yaml:"max_active"`
	MaxIdle   int    `yaml:"max_idle"`
	Db        int    `yaml:"db"`
}

type Db struct {
	Host     string `yaml:"host"`
	Port     int    `yaml:"port"`
	User     string `yaml:"user"`
	Password string `yaml:"password"`
	Database string `yaml:"database"`
}

var Setting = Set{}

func InitSetting() {
	file, err := ioutil.ReadFile("./app.yml")
	hlog.Info("初始化配置")

	err = yaml.Unmarshal(file, &Setting)
	if err != nil {
		hlog.Fatal("fail to yaml unmarshal:", err)
	}

}
